package com.feihong.txgw.ui.mvp;

import android.os.Bundle;
import android.support.annotation.NonNull;

import com.feihong.txgw.ui.activity.base.BaseActivity;
import com.feihong.txgw.ui.fragment.base.BaseFragment;
import com.feihong.txgw.ui.mvp.precenter.AbBasePrecenter;
import com.feihong.txgw.ui.mvp.view.IBaseFragment;
import com.feihong.txgw.message.LoginMessage;

/**
 * @Author wangziheng
 * @ProjectName txgw_app
 * @ClassName BaseMVPCompatFragment
 * @package com.feihong.txgw.ui.mvp
 * @data 2018/5/2 11:45
 * @Describe
 * @Change
 */
public abstract class BaseMVPCompatFragment<P extends AbBasePrecenter> extends BaseFragment implements IBaseFragment {
    public P mPrecenter;
    @Override
    public void initView() {
        mPrecenter = (P) initPresenter();
        mPrecenter.attachMV(this);
    }

    @Override
    public void bindData() {
    }

    @Override
    public void onUserLogin(LoginMessage loginMessage) {

    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        if(mPrecenter != null){
            mPrecenter.detachMV();
        }
    }

    @Override
    public void startNewActivityForResult(@NonNull Class<?> clz, Bundle bundle, int requestCode) {
        ((BaseActivity)_mActivity).startNewActivityForResult(clz,bundle,requestCode);
    }

    @Override
    public void startNewActivity(@NonNull Class<?> clz, Bundle bundle) {
        startNewActivityForResult(clz,bundle,-1);
    }

    @Override
    public void startNewActivity(Class<?> clz) {
        startNewActivityForResult(clz,null,-1);
    }

    @Override
    public BaseActivity getCurrentAcitivty() {
        return (BaseActivity) _mActivity;
    }
}
